home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 34.zip / BS1 part 34 / Aztec C 5.0a disk 3.adf / crt_src / _exit.c next >
C/C++ Source or Header  |  1989-10-27  |  2KB  |  79 lines

  1. /* Copyright (C) 1986,1987 by Manx Software Systems, Inc. */
  2.  
  3. #include <fcntl.h>
  4. #include <functions.h>
  5.  
  6. extern int _argc, _arg_len;
  7. extern char **_argv, *_arg_lin;
  8. extern struct WBStartup *WBenchMsg;
  9. extern void *DOSBase, *MathBase, *MathTransBase;
  10. extern void *MathIeeeDoubBasBase, *MathIeeeDoubTransBase;
  11. extern struct FileLock *_detach_curdir;
  12. extern void *_oldtrap, **_trapaddr;
  13.  
  14. void (*_cln)(void);
  15.  
  16. void
  17. _exit(int code)
  18. {
  19.     long ret = code;
  20.     register int fd;
  21.  
  22.     if (_devtab) {
  23.         for (fd = 0 ; fd < _numdev ; fd++)
  24.             close(fd);
  25.         FreeMem(_devtab, _numdev*(long)sizeof(struct _dev));
  26.     }
  27.     if (_cln)
  28.         (*_cln)();
  29.     if (_detach_curdir)                /* for DETACHed programs */
  30.         UnLock(_detach_curdir);
  31.     if (_trapaddr)                    /* clean up signal handling */
  32.         *_trapaddr = _oldtrap;
  33.     if (MathTransBase)
  34.         CloseLibrary(MathTransBase);
  35.     if (MathBase)
  36.         CloseLibrary(MathBase);
  37.     if (MathIeeeDoubBasBase)
  38.         CloseLibrary(MathIeeeDoubBasBase);
  39.     if (MathIeeeDoubTransBase)
  40.         CloseLibrary(MathIeeeDoubTransBase);
  41.     {
  42. #asm
  43.     mc68881
  44.     movem.l    a5/a6,-(sp)
  45.     move.l    4,a6                ;get ExecBase
  46.     btst.b    #4,$129(a6)            ;check for 68881 flag in AttnFlags
  47.     beq        1$                    ;skip if not
  48.     lea        2$,a5
  49.     jsr        -30(a6)                ;do it in supervisor mode
  50.     bra        1$
  51. 2$
  52.     clr.l    -(sp)
  53.     frestore (sp)+                ;reset the ffp stuff
  54.     rte                            ;and return
  55. 1$
  56.     move.l    (sp)+,a5/a6
  57. #endasm
  58.     }
  59.     if (WBenchMsg == 0) {
  60.         if (_arg_lin) {
  61.             FreeMem(_arg_lin, (long)_arg_len);
  62.             FreeMem(_argv, (long)(_argc+1)*sizeof(*_argv));
  63.         }
  64.     }
  65.     else {
  66.         Forbid();
  67.         ReplyMsg((struct Message *)WBenchMsg);
  68.     }
  69.     CloseLibrary(DOSBase);
  70.     {
  71. #asm
  72.         move.l    %%ret,d0        ;pick up return exit code
  73.         move.l    __savsp#,sp        ;get back original stack pointer
  74.         rts                        ;and exit
  75. #endasm
  76.     }
  77. }
  78.  
  79.